import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
import Location from "../views/Location.vue";
import Mine from "../views/Mine.vue";
import Login from "../views/Login.vue";
Vue.use(VueRouter);

const routes = [
	{
		path: "/",
		component: Home,
		name: "home",
	},
	{
		path: "/location",
		component: Location,
		name: "location",
	},
	{
		path: "/mine",
		component: Mine,
		name: "mine",
	},
	{
		path: "/login",
		component: Login,
		name: "login",
	},
	{
		path: "/mine/setting",
		name: "mine.setting",
		component: () =>
			import(
				/* webpackChunkName: "setting" */ "../views/setting/index.vue"
			),
	},
	{
		path: "/home/service",
		name: "home.service",
		component: () =>
			import(
				/* webpackChunkName: "service" */ "../views/service/index.vue"
			),
	},
	{
		path: "/home/service/list",
		name: "home.service.list",
		component: () =>
			import(
				/* webpackChunkName: "serviceList" */ "../views/service/list.vue"
			),
	},
	{
		path: "/home/notice/list",
		name: "home.notice.list",
		component: () =>
			import(
				/* webpackChunkName: "noticeList" */ "../views/notice/list.vue"
			),
	},
	{
		path: "/home/repair",
		name: "home.repair",
		component: () =>
			import(
				/* webpackChunkName: "repair" */ "../views/repair/index.vue"
			),
	},
	{
		path: "/home/house",
		name: "home.house",
		component: () =>
			import(/* webpackChunkName: "house" */ "../views/house/index.vue"),
	},
	{
		path: "/home/stall",
		name: "home.stall",
		component: () =>
			import(/* webpackChunkName: "stall" */ "../views/stall/index.vue"),
	},
	{
		path: "/mine/feedback",
		name: "mine.feedback",
		component: () =>
			import(
				/* webpackChunkName: "feedback" */ "../views/myFeedback/index.vue"
			),
	},
	{
		path: "/mine/house",
		name: "mine.house",
		component: () =>
			import(
				/* webpackChunkName: "house" */ "../views/myHouse/index.vue"
			),
	},
	{
		path: "/mine/stall",
		name: "mine.stall",
		component: () =>
			import(
				/* webpackChunkName: "stall" */ "../views/myStall/index.vue"
			),
	},
];

const router = new VueRouter({
	routes,
});

router.beforeEach((to, from, next) => {
	let isLogin = localStorage.getItem("userInfo");
	if (to.name !== "login" && !isLogin) {
		next("/login");
	} else {
		next();
	}
});
export default router;
